/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @return {string[]}
 */
var binaryTreePaths = function(root) {
    let res = [];
    if(!root)return res;

    function fun(node, path) {
        if(node.left)fun(node.left,path+"->"+node.left.val);
        if(node.right)fun(node.right,path+"->"+node.right.val);

        if(!node.left && !node.right){
            res.push(path);
            return;
        }
    }
    fun(root, root.val+"");

    return res;
};